package prefix.platform.loan;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

import prefix.platform.Constants;
import prefix.util.FormatUtil;
import prefix.util.OverallUtil;

public class Installment {

    private int m_number;

    private double m_balanceBefore;

    private double m_balanceAfter;

    private double m_monthlyAmount;

    private double m_principalPaid;

    private double m_interestPaid;

    private double m_totalPrincipalPaid;

    private double m_totalInterestPaid;

    private double m_totalAmountPaid;

    private Date m_dueDate;

    Installment(
            int number,
            double beforeBalance,
            double afterBalance,
            double amountPaid,
            double principalPaid,
            double totalPrincipalPaid,
            double totalAmountPaid,
            double interestPaid,
            double totalInterestPaid,
            Date duedate) {
        this.m_number = number;
        this.m_balanceBefore = beforeBalance;
        this.m_balanceAfter = afterBalance;
        this.m_monthlyAmount = amountPaid;
        this.m_principalPaid = principalPaid;
        this.m_interestPaid = interestPaid;
        this.m_totalPrincipalPaid = totalPrincipalPaid;
        this.m_totalAmountPaid = totalAmountPaid;
        this.m_totalInterestPaid = totalInterestPaid;
        this.m_dueDate = duedate;
    }

    public int getNumber() {
        return this.m_number;
    }

    public double getPrincipalBalanceBeforePymt() {
        return this.m_balanceBefore;
    }

    public double getPricinpalBalanceAfterPymt() {
        return this.m_balanceAfter;
    }

    public double getMonthlyPayment() {
        return this.m_monthlyAmount;
    }

    public double getToPrincipal() {
        return this.m_principalPaid;
    }

    public double getTotalPrincipalPaid() {
        return this.m_totalPrincipalPaid;
    }

    public double getToInterest() {
        return this.m_interestPaid;
    }

    public double getTotalInterestPaid() {
        return this.m_totalInterestPaid;
    }

    public double getTotalAmountPaid() {
        return this.m_totalAmountPaid;
    }

    public Date getDueDate() {
        return this.m_dueDate;
    }

    public double getPayOffAmnt() {
        BigDecimal payOff = OverallUtil.round2Decimal(this.getPrincipalBalanceBeforePymt() + this.getMonthlyPayment(),
                RoundingMode.CEILING);
        return payOff.doubleValue();
    }

    public String toString() {

        String p = "" + this.m_number + "" + FormatUtil.dateFormat("MMM d, yyyy", this.getDueDate()) + "   " +

        "openingBal = " + Constants.d7.format(this.getPrincipalBalanceBeforePymt()) + "  " + "payOff = "
                + Constants.d2.format(this.getPayOffAmnt()) + "    " +

                "MtlPayment = " + Constants.d7.format(this.getMonthlyPayment()) + " P&I= ["
                + Constants.d7.format(this.getToPrincipal()) + " ,  " + Constants.d7.format(this.getToInterest())
                + "]  ";

        //      TLCConstants.d7.format(this.getTotalPrincipalPaid()) + "  , " +
        //      TLCConstants.d7.format(this.getTotalInterestPaid()) + "\t\t" +
        //      TLCConstants.d7.format(this.getPricinpalBalanceAfterPymt()) 

        return p;
    }

}
